# -*- coding: utf-8 -*-
from datetime import timedelta
from ai_ageing_cusc_hi.dm.dm_complaints_warning_indicator_hi import jms_ai_group__dm_complaints_warning_indicator_hi
from ai_ageing_cusc_hi.dm.dm_complaints_warning_hi import jms_ai_group__dm_complaints_warning_hi

from airflow.exceptions import AirflowSkipException
from utils.operators.latest_only_bash_operator import BashOperator
import pendulum

cst = pendulum.timezone('Asia/Shanghai')

class WarningIndicatorMonitorBashOperator(BashOperator):
    def pre_execute(self, context):
        day = cst.convert(context['ti'].execution_date) + timedelta(hours=6)

        days_of_hours = ['00']

        if day.strftime('%H') in days_of_hours:
            print(f'{day.strftime("%H")} not in {days_of_hours}, should skip')
            raise AirflowSkipException()
        else:
            print(f'{day.strftime("%H")} in {days_of_hours}, run now')
            super().pre_execute(context)

jms_dm_oms__dm_complaints_warning_indicator_monitor_hi = WarningIndicatorMonitorBashOperator(
    task_id='jms_dm_oms__dm_complaints_warning_indicator_monitor_hi',
    execution_timeout=timedelta(hours=2),
    email=['jarl.huang@jtexpress.com','yl_bigdata@yl-scm.com'],
    bash_command="ai_ageing_cusc_hi/dm/dm_complaints_warning_indicator_monitor_hi/execute.sh",
    pool='spmi_apack',
    retries=1,
    pool_slots=2,
)

jms_dm_oms__dm_complaints_warning_indicator_monitor_hi << [
    jms_ai_group__dm_complaints_warning_indicator_hi,
    jms_ai_group__dm_complaints_warning_hi
]